package list;

public class MyArraylist {
	
	 Object vaule[];
	
	private int size;
	
	public MyArraylist(){
		this(2);
	}
	
	public MyArraylist(int size){
		vaule=new Object[size];
	}

	public void add(Object obj){
		
		vaule[size]=obj;
		
		size++;
		
		if(size>=vaule.length){
			int newlength=vaule.length*2;
	         Object newlist[]=new Object[newlength];
//		    for(int i=0;i<vaule.length;i++){
//		    	newlist[i]=vaule[i];
//		    }
	        
	         System.arraycopy(vaule, 0, newlist, 0, vaule.length);
	         
	        vaule=newlist;
		} 
		
	}
	
	public Object get(int index){
		if(index<0 || index>=vaule.length){
			try {
			 throw  new Exception();
				
		} catch (Exception e) {
			System.out.println("yichang");
		}
			
		}
		return vaule[index];
	}
	
	public static void main(String[] args) {
		
		MyArraylist list=new MyArraylist();
		list.add("222");
  	    list.add("2223");
  	    list.add("224");
	  
		
		System.out.println(list.get(2));
	}
	
}
